package com.droidwatcher.variables;

import com.alibaba.fastjson.JSON;
import com.droidwatcher.JsonEntity.HttpRequestHead;
import com.droidwatcher.JsonEntity.RegAndLoginJsonObj;
import com.droidwatcher.JsonEntity.RegistAndLoginEntityInfo;
import com.droidwatcher.lib.MessageType;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/1/24.
 */

public class RegAndLoginServerMsg implements IServerMessage {
    public MessageType type;

    private Map<String, Object> map;

    @Override
    public MessageType getType() {
            return type;
    }

    public RegAndLoginServerMsg(MessageType type){
        this.type = type ;
        this.map = new HashMap<String, Object>();
    }

    public RegAndLoginServerMsg addParam(String key, Object value) {
        map.put(key, value);
        return this;
    }

    @Override
    public String getJSONString() {

        RegAndLoginJsonObj obj = new RegAndLoginJsonObj() ;
        obj.setHead(new HttpRequestHead());

        RegistAndLoginEntityInfo registInfo  = new RegistAndLoginEntityInfo();

        registInfo.setPassword((String) map.get("pwd"));
        registInfo.setUsername((String) map.get("login"));

        obj.setInfo(registInfo);

        return JSON.toJSONString(obj);

    }

}
